<?php 
require_once  __DIR__ . '/includes/authenticate.php';
include_once './db_bb_connect.php';

require_once __DIR__ . '/includes/BasketbalStatsTableFunctions.php';

$basketbalfunctions = new BasketbalStatsTableFunctions();

?>

<!DOCTYPE html>
<html>
<head>
	<title>Game Stats Table</title>



<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <link rel="stylesheet" type="text/css" href="./css/style.css">

  <style>

  .editplayerstatsentry, .deleteplayerstatsentry {
  opacity:0.8;
}

.editplayerstatsentry:hover, .deleteplayerstatsentry:hover {
  opacity:1.0;
}

#editbuttonform{
  position:relative;
  left:0px;
  top:0px;
  margin-bottom:-15px;
}

#deletebuttonform{
  position:relative;
  left:40px;
  top:-15px;
  margin-bottom:-15px;
}

table {
  font-size: 14px;
  }


</style>

</head>
<body>

<div class="container-fluid">
  <div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-8" id="entirestatspage">	

<?php 

if (isset($_POST['season']) && isset($_POST['gamenumber']) && isset($_POST['opponent']) && isset($_POST['quarter']) && isset($_POST['location'])) {

	$season =  $_POST['season'];
	$gamenumber =  $_POST['gamenumber'];
	$opponent =  $_POST['opponent'];
	$quarter =  $_POST['quarter'];
	$location =  $_POST['location'];
	$coachteam =  $_POST['coachteam'];
	$type =  $_POST['type'];
	$date =  $_POST['date'];

	$score_coachteam = $_POST['score_coachteam']; 
	$score_opp = $_POST['score_opp'];

	if ($location == 'home') {
		echo "
		<h3>Game stats of $coachteam - $opponent </h3>
		<h4> 
		Date: $date <br>
		Result: $score_coachteam - $score_opp
		</h4>
		";
	} else if ($location == 'away') {
		echo "
		<h3>Game stats of $opponent - $coachteam </h3>
				<h4> 
		Date: $date <br>
		Result: $score_opp - $score_coachteam
		</h4>"
		;
	}

	echo "<br>";


	if ($quarter == "fullgame") {

		if ( $basketbalfunctions->CheckGameStatsAllQuartersAvailable($season, $gamenumber, $coachteam) ) {

			$basketbalfunctions->ShowGameStatsTableFullGameFromQuarters($season, $gamenumber, $coachteam);

		} elseif ($basketbalfunctions->CheckGameStatsTotalsAvailable($season, $gamenumber)){ 

			$basketbalfunctions->ShowGameStatsTableFullFromTotals($season, $gamenumber, $coachteam);

		} else {
				echo "<h4> Full game stats of $coachteam are not available. </h4> <br/>";
			}

		if ( $basketbalfunctions->CheckGameStatsAllQuartersAvailable($season, $gamenumber, $opponent) and $type != "Player" ) {

			$basketbalfunctions->ShowGameStatsTableFullGameFromQuarters($season, $gamenumber, $opponent);

		} elseif ( $type != "Player"){ 

			echo "<h4> Full game stats of $opponent are not available. <br> Some quarter stats are probably missing. </h4> <br/>";

			}

	} elseif ($quarter == "fullgameold") {

		$basketbalfunctions->ShowGameStatsTableFullFromTotals($season, $gamenumber, $coachteam);
		
	} elseif ($quarter == "firsthalf"){

		$basketbalfunctions->ShowCumuGameStatsTableHalfFromQuarters($season, $gamenumber, $coachteam, "firsthalf");

		$basketbalfunctions->ShowCumuGameStatsTableHalfFromQuarters($season, $gamenumber, $opponent, "firsthalf");

	} elseif ($quarter == "secondhalf"){

		$basketbalfunctions->ShowCumuGameStatsTableHalfFromQuarters($season, $gamenumber, $coachteam, "secondhalf");

		$basketbalfunctions->ShowCumuGameStatsTableHalfFromQuarters($season, $gamenumber, $opponent, "secondhalf");


	} else {

		$basketbalfunctions->ShowGameStatsTableSingleQuarter($season, $gamenumber, $coachteam, $quarter);

		$basketbalfunctions->ShowGameStatsTableSingleQuarter($season, $gamenumber, $opponent, $quarter);

	}
	

} else {

	echo "Incorrect Request";
}


?>

  </div>
    <div class="col-md-2"></div>
  </div>
</div>


</body>

</html>
